package com.mobile.check.views;

import android.app.Dialog;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.mobile.check.app.R;


/**
 * Created by Administrator on 2017/4/18.
 */

public class SubmitTipDialog extends Dialog {
    private TextView cancel_tv;
    private TextView submit_tv;
    private TextView titleTv;
    private TextView tipmessage_tv;
    private String message;

    SlectClickListener mSlectClickListener;

    public SubmitTipDialog(Context context, SlectClickListener listener, String message) {
        super(context, R.style.WinDialog);
        mSlectClickListener = listener;
        this.message = message;
        setContentView(R.layout.dialog_submittip);
        init();
    }

    public SubmitTipDialog(Context context, SlectClickListener listener) {
        super(context, R.style.WinDialog);
        mSlectClickListener = listener;
        setContentView(R.layout.dialog_submittip);
        init();
    }

    public void display(String title, String message, String leftText, String rightText) {
        Window dialogWindow = getWindow();
        //设置Dialog从窗体底部弹出
        dialogWindow.setGravity(Gravity.CENTER_VERTICAL);
        //获得窗体的属性
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        lp.y = 0;//设置Dialog距离底部的距离
//       将属性设置给窗体
        dialogWindow.setAttributes(lp);
        show();//显示对话框
        cancel_tv.setText(leftText);
        submit_tv.setText(rightText);
        titleTv.setText(title);
        tipmessage_tv.setText(message);
        if (TextUtils.isEmpty(leftText)) {
            cancel_tv.setVisibility(View.GONE);
        }
        setCanceledOnTouchOutside(true);
        setCancelable(true);

    }

    RecyclerView.OnScrollListener onScrollListener;


    private void init() {
        submit_tv = (TextView) findViewById(R.id.submit_tv);
        cancel_tv = (TextView) findViewById(R.id.cancel_tv);
        titleTv = (TextView) findViewById(R.id.titleTv);
        tipmessage_tv = (TextView) findViewById(R.id.tipmessage_tv);
        tipmessage_tv.setText(message);
        setOnlistener();
    }

    public void onlyCommitBtn() {
        cancel_tv.setVisibility(View.GONE);
    }

    private void setOnlistener() {
        submit_tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mSlectClickListener.submitClick();
                dismiss();
            }
        });
        cancel_tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mSlectClickListener.cancelClick();
                dismiss();
            }
        });
    }

    public interface SlectClickListener {
        void submitClick();


        void cancelClick();
    }


}
